package com.hzlj.position.dbsync.liaoning.controller;


import com.fz.common.base.dto.ResultDTO;
import com.fz.common.base.enums.CoordinateType;
import com.hzlj.position.config.common.dto.common.PositionAddDTO;
import com.hzlj.position.dbsync.common.config.PositionDbSyncConfig;
import com.hzlj.position.dbsync.liaoning.common.dto.zhizunWd.response.ZhizunWdDeviceLocationQueryResultDTO;
import com.hzlj.position.dbsync.liaoning.common.enums.AudioMsgType;
import com.hzlj.position.dbsync.liaoning.rest.ZhizunRest;
import com.hzlj.position.locate.common.dto.position.PositionAddResultDTO;
import com.hzlj.position.locate.common.util.PositionRestUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 智尊腕带
 *
 * @author lifh
 * @date 2023-03-28 18:38:38
 */
@Slf4j
@RestController
@RequestMapping("/position/locate/wd")
public class ZhizunWdController {
    @Resource
    private ZhizunRest zhizunRest;
    @Resource
    private PositionDbSyncConfig positionDbSyncConfig;


    /**
     * 发送查找设备指令
     */
    @GetMapping("/findDevice/{deviceCode}")
    public ResultDTO<Boolean> deviceCode(@PathVariable("deviceCode") String deviceCode) {
        zhizunRest.findDevice(deviceCode);
        return ResultDTO.ok();
    }

    /**
     * 获取位置
     */
    @GetMapping("/locate/{deviceCode}")
    public PositionAddResultDTO locate(@PathVariable("deviceCode") String deviceCode) {
        ZhizunWdDeviceLocationQueryResultDTO deviceLocation = zhizunRest.getDeviceLocation(deviceCode);
        PositionAddDTO convert = deviceLocation.convert();
        convert.setReturnPosition(true);
        return PositionRestUtil.add(CoordinateType.GCJ02,positionDbSyncConfig.getUrl(), convert);
    }

    /**
     * 设置低电量报警
     */
    @PostMapping("/updateLowbat/{deviceCode}")
    public ResultDTO<Boolean> updateLowbat(@PathVariable("deviceCode") String deviceCode,
                                           @RequestParam(defaultValue = "true") boolean lowbat) {
        zhizunRest.updateLowbat(deviceCode, lowbat);
        return ResultDTO.ok();
    }

    /**
     * 远程关机
     */
    @PostMapping("/shutdown/{deviceCode}")
    public ResultDTO<Boolean> shutdown(@PathVariable("deviceCode") String deviceCode) {
        zhizunRest.shutdown(deviceCode);
        return ResultDTO.ok();
    }

    /**
     * 设置定位频率
     */
    @PostMapping("/updateLocateInterval/{deviceCode}")
    public ResultDTO<Boolean> updateLocationFrequency(@PathVariable("deviceCode") String deviceCode,
                                                      @RequestParam(defaultValue = "3600") String locateInterval) {
        zhizunRest.updateLocationFrequency(deviceCode, locateInterval);
        return ResultDTO.ok();
    }


    /**
     * 发送语音消息(语音)
     */
    @PostMapping("/sendAudioMsg/{deviceCode}")
    public ResultDTO<Boolean> sendAudioMsg(@PathVariable("deviceCode") String deviceCode,
                                           @RequestParam(defaultValue = "1") String audioMsgType) {
        zhizunRest.sendAudioMsg(deviceCode, AudioMsgType.of(audioMsgType));
        return ResultDTO.ok();
    }

    /**
     * 发送语音消息(文本)
     */
    @PostMapping("/sendTextMsg/{deviceCode}")
    public ResultDTO<Boolean> sendTextMsg(@PathVariable("deviceCode") String deviceCode,
                                         @RequestParam String msg) {
        zhizunRest.sendTextMsg(deviceCode, msg);
        return ResultDTO.ok();
    }
}

